home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 22 / macformat_22.iso / Shareware / Programación / The Gray Council 1.1 / source / MacApp / GrayCouncilMA.cpp next >
Encoding:
Text File  |  1996-08-08  |  61.4 KB  |  2,443 lines  |  [TEXT/CWIE]

  1. //
  2. // GrayCouncilMA
  3. // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
  4. //
  5. // MacApp adapter classes for core Gray Council.
  6. //
  7. // Before using any of the GrayCouncil source code, read and
  8. // follow the licensing info in the accompanying documentation
  9. // or contact:
  10. //   <trygve@kagi.com>
  11. //   <http://www.kagi.com/authors/trygve/>
  12. //
  13. // GrayCouncil provides a set of standard C++ classes that implement
  14. // the standard Apple Grayscale Appearance. The core classes do not
  15. // require any other code such as a particular class framework.
  16. //
  17. // This file defines a set of helper classes that derive from standard
  18. // MacApp view classes, and interface with the core Gray Council code.
  19. // There are also a couple of adorner subclasses for attaching to windows
  20. // and list boxes to get the correct background color or target border.
  21. //
  22. // Normally, to use a GrayCouncil MacApp class, you can simply change the
  23. // class name of the subview in your resource file or AdLib view to the
  24. // class name of the appropriate Gray Council MacApp adapter class. For
  25. // example, to use the GC pushbutton, create a normal TButton subview,
  26. // and set its class name to AGAPushButtonMA. Voila.
  27. //
  28. // A couple of the classes use the userData field of the subview to specify
  29. // additional information such as icon IDs, string resource IDs, etc.
  30. //
  31. // Each class here that interfaces to a core AGAObject has a public
  32. // member variable called mAGAObject that points to the actual AGAObject
  33. // subclass object. Certain extended object settings (such as mixed-state
  34. // buttons, proportional and live scrolling, etc.) require you to call
  35. // the AGAObject to set it. The member variable is made public to keep
  36. // these MacApp classes as lightweight as possible; you make the call,
  37. // rather than using myriad new functions of the MacApp AGA subclasses.
  38. //
  39. // Classes defined below:
  40. //    AGAPushButtonMA -- TButton subclass for AGAPushButton
  41. //    AGACheckBoxMA -- TCheckBox subclass for AGACheckBox
  42. //    AGARadioButtonMA -- TRadio subclass for AGARadioButton
  43. //    AGAIconPushButtonMA -- AGAPushButtonMA (TButton) subclass for AGAIconPushButton
  44. //    AGAIconCheckBoxMA -- AGACheckBoxMA (TCheckBox) subclass for AGAIconCheckBox
  45. //    AGAIconRadioButtonMA -- AGARadioButtonMA (TRadio) subclass for AGAIconRadioButton
  46. //    AGAScrollBarMA -- TScrollBar subclass for AGAScrollBar
  47. //    AGAScrollerScrollBarMA -- TScrollerScrollBar subclass for AGAScrollBar
  48. //        Remember the difference between TScrollBar and TScrollerScrollBar!
  49. //    AGASliderMA -- TControl subclass for AGASlider
  50. //    AGABackgroundAdornerMA -- TAdorner subclass that you should attach to
  51. //        typical modeless windows; gives it the proper modeless gray background
  52. //    AGAModalBackgroundAdornerMA -- AGABackgroundAdornerMA (TAdorner) subclass
  53. //        that you should attach to modal windows (i.e., things you PoseModally);
  54. //        gives it the proper modal gray background
  55. //    AGAWhiteBackgroundAdornerMA -- TAdorner subclass you should attach to any
  56. //        view that needs a white background but lives in a gray background window
  57. //        (e.g., TEditText, TScroller containing grid, etc.)
  58. //    AGABorderFrameAdornerMA -- TAdorner subclass that you can attach to any
  59. //        view that needs a "3D" sunken frame around it (e.g., the same things
  60. //        that need a white background adorner)
  61. //    AGAPopupMA -- TPopup subclass for AGAPopupMenu
  62. //    AGAStaticTextMA -- TStaticText subclass for AGAStaticText 
  63. //    AGALittleArrowsMA -- TControl subclass for AGALittleArrows
  64. //    AGADisclosureTriangleMA -- TControl subclass for AGADisclosureTriangle
  65. //    AGAProgressIndicatorMA -- TControl subclass for AGAProgressIndicator
  66. //    AGASeparatorMA -- TView subclass for AGASeparator
  67. //    AGATargetBorderViewMA -- TTargetBorderView subclass that draws AGA-style
  68. //        target border frame
  69. //    AGAClusterMA -- TCluster subclass for AGAGroupBox
  70. //    AGASecondaryClusterMA -- AGAClusterMA (TCluster) subclass for AGAGroupBox
  71. //        with secondary box style set
  72. //
  73.  
  74. #include "GrayCouncilMA.h"
  75.  
  76. #include <plstringfuncs.h>
  77.  
  78. OSErr InitGrayCouncilMA()
  79.     {
  80.     //
  81.     // Register our dynamically instantiated view subclasses.
  82.     //
  83.  
  84.     MA_REGISTER_CLASS(AGAPushButtonMA);
  85.     MA_REGISTER_CLASS(AGACheckBoxMA);
  86.     MA_REGISTER_CLASS(AGARadioButtonMA);
  87.     MA_REGISTER_CLASS(AGAIconPushButtonMA);
  88.     MA_REGISTER_CLASS(AGAIconCheckBoxMA);
  89.     MA_REGISTER_CLASS(AGAIconRadioButtonMA);
  90.     MA_REGISTER_CLASS(AGAScrollBarMA);
  91.     MA_REGISTER_CLASS(AGAScrollerScrollBarMA);
  92.     MA_REGISTER_CLASS(AGASliderMA);
  93.     MA_REGISTER_CLASS(AGABackgroundAdornerMA);
  94.     MA_REGISTER_CLASS(AGAModalBackgroundAdornerMA);
  95.     MA_REGISTER_CLASS(AGAPopupMA);
  96.     MA_REGISTER_CLASS(AGAStaticTextMA);
  97.     MA_REGISTER_CLASS(AGALittleArrowsMA);
  98.     MA_REGISTER_CLASS(AGAWhiteBackgroundAdornerMA);
  99.     MA_REGISTER_CLASS(AGABorderFrameAdornerMA);
  100.     MA_REGISTER_CLASS(AGADisclosureTriangleMA);
  101.     MA_REGISTER_CLASS(AGAProgressIndicatorMA);
  102.     MA_REGISTER_CLASS(AGASeparatorMA);
  103.     MA_REGISTER_CLASS(AGATargetBorderViewMA);
  104.     MA_REGISTER_CLASS(AGATargetBorderFrameViewMA);
  105.     MA_REGISTER_CLASS(AGAGroupBoxMA);
  106.     MA_REGISTER_CLASS(AGASecondaryGroupBoxMA);
  107.  
  108.     // Do Core Gray Council initialization.
  109.     return InitGrayCouncil();
  110.     }
  111.  
  112. static void SetAGAObjectFrame(TView* itsView,
  113.                                 AGAObject* theAGAObject,
  114.                                 const VRect& newViewFrame,
  115.                                 Boolean redraw)
  116.     {
  117.     if (theAGAObject != NULL)
  118.         {
  119.         VRect    viewRect(0, 0, itsView->fSize.h, itsView->fSize.v);
  120.         CRect    qdRect;
  121.         
  122.         itsView->ViewToQDRect(viewRect, qdRect);
  123.  
  124.         theAGAObject->SetObjectBounds(qdRect, AGAObject::kDontRedraw);
  125.         }
  126.     }
  127.  
  128. //
  129. // AGAPushButtonMA ----------------------------------------------------
  130. //
  131.  
  132. #undef Inherited
  133. #define Inherited TButton
  134.  
  135. MA_DEFINE_CLASS_M1(AGAPushButtonMA, Inherited);
  136.  
  137. AGAPushButtonMA::AGAPushButtonMA()
  138.     {
  139.     mAGAObject = NULL;
  140.     }
  141.  
  142. AGAPushButtonMA::~AGAPushButtonMA()
  143.     {
  144.     // Delete AGA object if we successfully allocated it.
  145.  
  146.     if (mAGAObject != NULL)
  147.         delete mAGAObject;
  148.     }
  149.  
  150. void AGAPushButtonMA::IAGAPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel)
  151.     {
  152.     this->IButton(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel);
  153.  
  154.     this->CreateAGAObject();
  155.     }
  156.  
  157. void AGAPushButtonMA::DoPostCreate(TDocument* itsDocument)
  158.     {
  159.     // Create and set up the AGAObject.
  160.  
  161.     Inherited::DoPostCreate(itsDocument);
  162.     
  163.     this->CreateAGAObject();
  164.     }
  165.  
  166. void AGAPushButtonMA::CreateAGAObject()
  167.     {
  168.     // Instantiate the particular AGAObject subclass.
  169.     
  170.     (void) this->SetCMgrVisibility(FALSE);
  171.  
  172.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  173.     CRect    bounds;
  174.     CStr255    viewTitle;
  175.     
  176.     this->ViewToQDRect(viewRect, bounds);
  177.     this->GetText(viewTitle);
  178.  
  179.     FailNIL(mAGAObject = new AGAPushButton(bounds, AGATextStyle(fTextStyle), viewTitle));
  180.  
  181.     if (! fEnabled)
  182.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  183.  
  184.     //
  185.     // We implement the default button outline by checking for the
  186.     // presence of the TRRectAdorner by std ID, tossing it, and
  187.     // telling the AGA button object that it is a default button.
  188.     //
  189.  
  190.     TAdorner*    rrectAdorner = this->FindRRectAdorner();
  191.     if (rrectAdorner)
  192.         {
  193.         this->DeleteAdorner(rrectAdorner, kDontInvalidate);
  194.         mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameInside);
  195.         }
  196.     }
  197.  
  198. void AGAPushButtonMA::Draw(const VRect& area)
  199.     {
  200.     // Let the AGAObject draw itself.
  201.  
  202.     if (mAGAObject != NULL)
  203.         mAGAObject->DrawObject();
  204.     }
  205.  
  206. void AGAPushButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  207.     {
  208.     // Let the MacApp and AGA objects update their locations.
  209.  
  210.     Inherited::SetFrame(newFrame, invalidate);
  211.     
  212.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  213.     }
  214.  
  215. void AGAPushButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  216.     {
  217.     // Let the AGAObject track the mouse; if tracking succeeds
  218.     // handle our event number.
  219.  
  220.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  221.         this->HandleEvent(fEventNumber, this, NULL);
  222.     }
  223.  
  224. void AGAPushButtonMA::HiliteState(Boolean state, Boolean redraw)
  225.     {
  226.     // Let the AGAPushButton draw in the specified state.
  227.  
  228.     if ((mAGAObject != NULL) && this->Focus())
  229.         mAGAObject->DrawButton(state);
  230.     }
  231.  
  232. void AGAPushButtonMA::Hilite()
  233.     {
  234.     // Let the AGAPushButton draw in pressed state.
  235.  
  236.     if ((mAGAObject != NULL) && this->Focus())
  237.         mAGAObject->DrawButton(AGAObject::kPressed);
  238.     }
  239.  
  240. void AGAPushButtonMA::DimState(Boolean state, Boolean redraw)
  241.     {
  242.     // Set the AGAObject's enable state.
  243.  
  244.     if ((mAGAObject != NULL) && this->Focus())
  245.         mAGAObject->SetEnable(!state, redraw);
  246.     }
  247.  
  248. void AGAPushButtonMA::Dim()
  249.     {
  250.     // Set the AGAObject's enable state, with immediate redraw.
  251.  
  252.     if (mAGAObject != NULL)
  253.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  254.     }
  255.  
  256. TAdorner* AGAPushButtonMA::FindRRectAdorner()
  257.     {
  258.     // Return the TRRectAdorner, if any, that is attached to
  259.     // this push button.
  260.  
  261.     TAdorner*    foundAdorner = NULL;
  262.  
  263.     if (fAdorners != NULL)
  264.         {
  265.         CAdornerIterator    iter(this);
  266.  
  267.         for (TAdorner* theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
  268.             {
  269.             if (MA_MEMBER(theAdorner, TRRectAdorner))
  270.                 foundAdorner = theAdorner;
  271.             }
  272.         }
  273.  
  274.     return foundAdorner;
  275.     }
  276.  
  277. //
  278. // AGACheckBoxMA ----------------------------------------------------
  279. //
  280.  
  281. #undef Inherited
  282. #define Inherited TCheckBox
  283.  
  284. MA_DEFINE_CLASS_M1(AGACheckBoxMA, Inherited);
  285.  
  286. AGACheckBoxMA::AGACheckBoxMA()
  287.     {
  288.     mAGAObject = NULL;
  289.     }
  290.  
  291. AGACheckBoxMA::~AGACheckBoxMA()
  292.     {
  293.     // Delete AGA object if we successfully allocated it.
  294.  
  295.     if (mAGAObject != NULL)
  296.         delete mAGAObject;
  297.     }
  298.  
  299. void AGACheckBoxMA::IAGACheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  300.     {
  301.     this->ICheckBox(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  302.  
  303.     this->CreateAGAObject();
  304.     }
  305.  
  306. void AGACheckBoxMA::DoPostCreate(TDocument* itsDocument)
  307.     {
  308.     // Create and set up the AGAObject.
  309.  
  310.     Inherited::DoPostCreate(itsDocument);
  311.     
  312.     this->CreateAGAObject();
  313.     }
  314.  
  315. void AGACheckBoxMA::CreateAGAObject()
  316.     {
  317.     // Instantiate the particular AGAObject subclass.
  318.  
  319.     (void) this->SetCMgrVisibility(FALSE);
  320.  
  321.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  322.     CRect    bounds;
  323.     CStr255    viewTitle;
  324.     
  325.     this->ViewToQDRect(viewRect, bounds);
  326.     this->GetText(viewTitle);
  327.  
  328.     FailNIL(mAGAObject = new AGACheckBox(bounds, AGATextStyle(fTextStyle), viewTitle, AGAObject::kNoAutomaticState));
  329.  
  330.     if (this->GetLongVal() != 0)
  331.         mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw);
  332.  
  333.     if (! fEnabled)
  334.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  335.     }
  336.  
  337. void AGACheckBoxMA::Draw(const VRect& area)
  338.     {
  339.     // Let the AGAObject draw itself.
  340.  
  341.     if (mAGAObject != NULL)
  342.         mAGAObject->DrawObject();
  343.     }
  344.  
  345. void AGACheckBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  346.     {
  347.     // Let the MacApp and AGA objects update their locations.
  348.  
  349.     Inherited::SetFrame(newFrame, invalidate);
  350.     
  351.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  352.     }
  353.  
  354. void AGACheckBoxMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  355.     {
  356.     // Let the AGAObject track the mouse; if tracking succeeds
  357.     // handle our event number.
  358.  
  359.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  360.         this->HandleEvent(fEventNumber, this, NULL);
  361.     }
  362.  
  363. void AGACheckBoxMA::HiliteState(Boolean state, Boolean redraw)
  364.     {
  365.     // Let the AGACheckBox draw in the specified state.
  366.  
  367.     if ((mAGAObject != NULL) && this->Focus())
  368.         mAGAObject->DrawButton(state);
  369.     }
  370.  
  371. void AGACheckBoxMA::Hilite()
  372.     {
  373.     // Let the AGACheckBox draw in pressed state.
  374.  
  375.     if ((mAGAObject != NULL) && this->Focus())
  376.         mAGAObject->DrawButton(AGAObject::kPressed);
  377.     }
  378.  
  379. void AGACheckBoxMA::DimState(Boolean state, Boolean redraw)
  380.     {
  381.     // Set the AGAObject's enable state.
  382.  
  383.     if (mAGAObject != NULL)
  384.         {
  385.         Boolean    wantRedraw = redraw && this->Focus();
  386.  
  387.         mAGAObject->SetEnable(!state, wantRedraw);
  388.         }
  389.     }
  390.  
  391. void AGACheckBoxMA::Dim()
  392.     {
  393.     // Set the AGAObject's enable state, with immediate redraw.
  394.  
  395.     if (mAGAObject != NULL)
  396.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  397.     }
  398.  
  399. Boolean AGACheckBoxMA::IsOn()
  400.     {
  401.     // Return true if it's on.
  402.  
  403.     if (mAGAObject == NULL)
  404.         return Inherited::IsOn();
  405.     else
  406.         return mAGAObject->GetValue() == AGACheckBox::kCheckBoxOn;
  407.     }
  408.  
  409. void AGACheckBoxMA::SetState(Boolean state, Boolean redraw)
  410.     {
  411.     // Set the state to on or off.
  412.  
  413.     if (mAGAObject != NULL)
  414.         {
  415.         Boolean    wantRedraw = redraw && this->Focus();
  416.  
  417.         mAGAObject->SetValue(state, wantRedraw);
  418.         }
  419.     }
  420.  
  421. void AGACheckBoxMA::Toggle(Boolean redraw)
  422.     {
  423.     // Toggle the state between on and off.
  424.  
  425.     if (mAGAObject != NULL)
  426.         {
  427.         Boolean    wantRedraw = redraw && this->Focus();
  428.  
  429.         this->SetState(! this->IsOn(), wantRedraw);
  430.         }
  431.     }
  432.  
  433. void AGACheckBoxMA::ToggleIf(Boolean matchState, Boolean redraw)
  434.     {
  435.     // Toggle the state if it's currently in the specified state.
  436.  
  437.     if (mAGAObject != NULL)
  438.         if (this->IsOn() == matchState)
  439.             {
  440.             Boolean    wantRedraw = redraw && this->Focus();
  441.  
  442.             this->SetState(! this->IsOn(), wantRedraw);
  443.             }
  444.     }
  445.  
  446. //
  447. // AGARadioButtonMA ----------------------------------------------------
  448. //
  449.  
  450. #undef Inherited
  451. #define Inherited TRadio
  452.  
  453. MA_DEFINE_CLASS_M1(AGARadioButtonMA, Inherited);
  454.  
  455. AGARadioButtonMA::AGARadioButtonMA()
  456.     {
  457.     mAGAObject = NULL;
  458.     }
  459.  
  460. AGARadioButtonMA::~AGARadioButtonMA()
  461.     {
  462.     // Delete AGA object if we successfully allocated it.
  463.  
  464.     if (mAGAObject != NULL)
  465.         delete mAGAObject;
  466.     }
  467.  
  468. void AGARadioButtonMA::IAGARadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  469.     {
  470.     this->IRadio(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  471.  
  472.     this->CreateAGAObject();
  473.     }
  474.  
  475. void AGARadioButtonMA::DoPostCreate(TDocument* itsDocument)
  476.     {
  477.     // Create and set up the AGAObject.
  478.  
  479.     Inherited::DoPostCreate(itsDocument);
  480.     
  481.     this->CreateAGAObject();
  482.     }
  483.  
  484. void AGARadioButtonMA::CreateAGAObject()
  485.     {
  486.     // Instantiate the particular AGAObject subclass.
  487.  
  488.     (void) this->SetCMgrVisibility(FALSE);
  489.  
  490.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  491.     CRect    bounds;
  492.     CStr255    viewTitle;
  493.     
  494.     this->ViewToQDRect(viewRect, bounds);
  495.     this->GetText(viewTitle);
  496.  
  497.     FailNIL(mAGAObject = new AGARadioButton(bounds, AGATextStyle(fTextStyle), viewTitle, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState));
  498.  
  499.     if (this->GetLongVal() != 0)
  500.         mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw);
  501.  
  502.     if (! fEnabled)
  503.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  504.     }
  505.  
  506. void AGARadioButtonMA::Draw(const VRect& area)
  507.     {
  508.     // Let the AGAObject draw itself.
  509.  
  510.     if (mAGAObject != NULL)
  511.         mAGAObject->DrawObject();
  512.     }
  513.  
  514. void AGARadioButtonMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  515.     {
  516.     // Let the MacApp and AGA objects update their locations.
  517.  
  518.     Inherited::SetFrame(newFrame, invalidate);
  519.     
  520.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  521.     }
  522.  
  523. void AGARadioButtonMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  524.     {
  525.     // Let the AGAObject track the mouse; if tracking succeeds
  526.     // handle our event number.
  527.  
  528.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  529.         this->HandleEvent(fEventNumber, this, NULL);
  530.     }
  531.  
  532. void AGARadioButtonMA::HiliteState(Boolean state, Boolean redraw)
  533.     {
  534.     // Let the AGARadioButton draw in the specified state.
  535.  
  536.     if ((mAGAObject != NULL) && this->Focus())
  537.         mAGAObject->DrawButton(state);
  538.     }
  539.  
  540. void AGARadioButtonMA::Hilite()
  541.     {
  542.     // Let the AGARadioButton draw in pressed state.
  543.  
  544.     if ((mAGAObject != NULL) && this->Focus())
  545.         mAGAObject->DrawButton(AGAObject::kPressed);
  546.     }
  547.  
  548. void AGARadioButtonMA::DimState(Boolean state, Boolean redraw)
  549.     {
  550.     // Set the AGAObject's enable state.
  551.  
  552.     if (mAGAObject != NULL)
  553.         {
  554.         Boolean    wantRedraw = redraw && this->Focus();
  555.  
  556.         mAGAObject->SetEnable(!state, wantRedraw);
  557.         }
  558.     }
  559.  
  560. void AGARadioButtonMA::Dim()
  561.     {
  562.     // Set the AGAObject's enable state, with immediate redraw.
  563.  
  564.     if (mAGAObject != NULL)
  565.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  566.     }
  567.  
  568. Boolean AGARadioButtonMA::IsOn()
  569.     {
  570.     // Return true if it's on.
  571.  
  572.     if (mAGAObject == NULL)
  573.         return Inherited::IsOn();
  574.     else
  575.         return mAGAObject->GetValue() == AGARadioButton::kRadioButtonOn;
  576.     }
  577.  
  578. void AGARadioButtonMA::SetState(Boolean state, Boolean redraw)
  579.     {
  580.     // Set the state to on or off.
  581.  
  582.     if (mAGAObject != NULL)
  583.         {
  584.         Boolean    wantRedraw = redraw && this->Focus();
  585.  
  586.         mAGAObject->SetValue(state, wantRedraw);
  587.         }
  588.     }
  589.  
  590. void AGARadioButtonMA::Toggle(Boolean redraw)
  591.     {
  592.     // Toggle the state between on and off.
  593.  
  594.     if (mAGAObject != NULL)
  595.         {
  596.         Boolean    wantRedraw = redraw && this->Focus();
  597.  
  598.         this->SetState(! this->IsOn(), wantRedraw);
  599.         }
  600.     }
  601.  
  602. void AGARadioButtonMA::ToggleIf(Boolean matchState, Boolean redraw)
  603.     {
  604.     // Toggle the state if it's currently in the specified state.
  605.  
  606.     if (mAGAObject != NULL)
  607.         if (this->IsOn() == matchState)
  608.             {
  609.             Boolean    wantRedraw = redraw && this->Focus();
  610.  
  611.             this->SetState(! this->IsOn(), wantRedraw);
  612.             }
  613.     }
  614.  
  615. //
  616. // This function is used by all 3 icon button classes to get the icon type.
  617. //
  618.  
  619. static UInt32 GetIconType(SInt16 width)
  620.     {
  621.     if (width > 39)
  622.         return MIconButtonObject::kLargeIcon;
  623.     else if (width > 21)
  624.         return MIconButtonObject::kSmallIcon;
  625.     else
  626.         return MIconButtonObject::kMiniIcon;
  627.     }
  628.  
  629. //
  630. // AGAIconPushButtonMA ----------------------------------------------------
  631. //
  632.  
  633. #undef Inherited
  634. #define Inherited AGAPushButtonMA
  635.  
  636. MA_DEFINE_CLASS_M1(AGAIconPushButtonMA, Inherited);
  637.  
  638. void AGAIconPushButtonMA::IAGAIconPushButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel)
  639.     {
  640.     this->IAGAPushButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel);
  641.     }
  642.  
  643. void AGAIconPushButtonMA::CreateAGAObject()
  644.     {
  645.     // Instantiate the particular AGAObject subclass.
  646.  
  647.     (void) this->SetCMgrVisibility(FALSE);
  648.  
  649.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  650.     CRect    bounds;
  651.     
  652.     this->ViewToQDRect(viewRect, bounds);
  653.  
  654.     ResNumber    iconID = fUserArea;
  655.     UInt32        iconType = GetIconType(bounds.GetLength(hSel));    // static fn above
  656.  
  657.     FailNIL(mAGAObject = new AGAIconPushButton(bounds, iconID, iconType));
  658.     }
  659.  
  660. //
  661. // AGAIconCheckBoxMA ----------------------------------------------------
  662. //
  663.  
  664. #undef Inherited
  665. #define Inherited AGACheckBoxMA
  666.  
  667. MA_DEFINE_CLASS_M1(AGAIconCheckBoxMA, Inherited);
  668.  
  669. void AGAIconCheckBoxMA::IAGAIconCheckBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  670.     {
  671.     this->IAGAIconCheckBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  672.     }
  673.  
  674. void AGAIconCheckBoxMA::CreateAGAObject()
  675.     {
  676.     // Instantiate the particular AGAObject subclass.
  677.  
  678.     (void) this->SetCMgrVisibility(FALSE);
  679.  
  680.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  681.     CRect    bounds;
  682.     
  683.     this->ViewToQDRect(viewRect, bounds);
  684.  
  685.     ResNumber    iconID = fUserArea;
  686.     UInt32        iconType = GetIconType(bounds.GetLength(hSel));    // static fn above
  687.  
  688.     FailNIL(mAGAObject = new AGAIconCheckBox(bounds, AGAObject::kNoAutomaticState, iconID, iconID, iconType));
  689.  
  690.     if (this->GetLongVal() != 0)
  691.         mAGAObject->SetValue(AGACheckBox::kCheckBoxOn, AGAObject::kDontRedraw);
  692.  
  693.     if (! fEnabled)
  694.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  695.     }
  696.  
  697. //
  698. // AGAIconRadioButtonMA ----------------------------------------------------
  699. //
  700.  
  701. #undef Inherited
  702. #define Inherited AGARadioButtonMA
  703.  
  704. MA_DEFINE_CLASS_M1(AGAIconRadioButtonMA, Inherited);
  705.  
  706. void AGAIconRadioButtonMA::IAGAIconRadioButtonMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const CStr255& itsLabel, Boolean isTurnedOn)
  707.     {
  708.     this->IAGARadioButtonMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, isTurnedOn);
  709.     }
  710.  
  711. void AGAIconRadioButtonMA::CreateAGAObject()
  712.     {
  713.     // Instantiate the particular AGAObject subclass.
  714.  
  715.     (void) this->SetCMgrVisibility(FALSE);
  716.  
  717.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  718.     CRect    bounds;
  719.     
  720.     this->ViewToQDRect(viewRect, bounds);
  721.  
  722.     ResNumber    iconID = fUserArea;
  723.     UInt32        iconType = GetIconType(bounds.GetLength(hSel));    // static fn above
  724.  
  725.     FailNIL(mAGAObject = new AGAIconRadioButton(bounds, kNoGroupID, kNoGroupID, AGAObject::kNoAutomaticState, iconID, iconID, iconType));
  726.  
  727.     if (this->GetLongVal() != 0)
  728.         mAGAObject->SetValue(AGARadioButton::kRadioButtonOn, AGAObject::kDontRedraw);
  729.  
  730.     if (! fEnabled)
  731.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  732.     }
  733.  
  734. //
  735. // AGAScrollBarMA ----------------------------------------------------
  736. //
  737.  
  738. #undef Inherited
  739. #define Inherited TScrollBar
  740.  
  741. MA_DEFINE_CLASS_M1(AGAScrollBarMA, Inherited);
  742.  
  743. AGAScrollBarMA::AGAScrollBarMA()
  744.     {
  745.     mNotificationRoutine = NULL;
  746.     mAGAObject = NULL;
  747.     }
  748.  
  749. AGAScrollBarMA::~AGAScrollBarMA()
  750.     {
  751.     // Delete AGA object if we successfully allocated it.
  752.  
  753.     if (mAGAObject != NULL)
  754.         delete mAGAObject;
  755.     }
  756.  
  757. void AGAScrollBarMA::IAGAScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsVal, long itsMin, long itsMax)
  758.     {
  759.     this->IScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsVal, itsMin, itsMax);
  760.  
  761.     this->CreateAGAObject();
  762.     }
  763.  
  764. void AGAScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  765.     {
  766.     // Save the notification routine fn pointer and user data
  767.     // for notification handling.
  768.  
  769.     mNotificationRoutine = notificationRoutine;
  770.     mUserData = userData;
  771.     }
  772.  
  773. void AGAScrollBarMA::HandleNotification(SInt32 dataValue)
  774.     {
  775.     // Update the scrollbar value, call the installed notification
  776.     // function, and propagate our event number.
  777.  
  778.     this->SetLongVal(dataValue, kDontRedraw);
  779.  
  780.     if (mNotificationRoutine != NULL)
  781.         (*mNotificationRoutine)(this, dataValue, mUserData);
  782.     
  783.     this->HandleEvent(fEventNumber, this, NULL);
  784.  
  785.     (void) this->Focus();    // HandleEvent may have caused another view to draw
  786.     }
  787.  
  788. void AGAScrollBarMA::DoPostCreate(TDocument* itsDocument)
  789.     {
  790.     // Create and set up the AGAObject.
  791.  
  792.     Inherited::DoPostCreate(itsDocument);
  793.     
  794.     this->CreateAGAObject();
  795.     }
  796.  
  797. void AGAScrollBarMA::CreateAGAObject()
  798.     {
  799.     // Instantiate the particular AGAObject subclass.
  800.  
  801.     (void) this->SetCMgrVisibility(FALSE);
  802.  
  803.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  804.     CRect    bounds;
  805.     
  806.     this->ViewToQDRect(viewRect, bounds);
  807.  
  808.     FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal()));
  809.     
  810.     mAGAObject->InstallNotificationRoutine(AGAScrollBarMA::RealAGANotifier, this);
  811.  
  812.     if (! fEnabled)
  813.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  814.     }
  815.  
  816. void AGAScrollBarMA::Draw(const VRect& area)
  817.     {
  818.     // Let the AGAObject draw itself.
  819.  
  820.     if (mAGAObject != NULL)
  821.         mAGAObject->DrawObject();
  822.     }
  823.  
  824. void AGAScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  825.     {
  826.     // Let the MacApp and AGA objects update their locations.
  827.  
  828.     Inherited::SetFrame(newFrame, invalidate);
  829.     
  830.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  831.     }
  832.  
  833. void AGAScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  834.     {
  835.     // Catch all value changes here and synchronize the
  836.     // AGAScrollBar accordingly.
  837.  
  838.     Inherited::SetLongVal(itsVal, redraw);
  839.     
  840.     if (mAGAObject != NULL)
  841.         {
  842.         Boolean    wantRedraw = redraw && this->Focus();
  843.  
  844.         mAGAObject->SetValue(itsVal, wantRedraw);
  845.         }
  846.     }
  847.  
  848. void AGAScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  849.     {
  850.     // Let the AGAObject track the mouse. Don't call HandleEvent;
  851.     // it has already been handled through HandleNotification.
  852.  
  853.     (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse));
  854.     }
  855.  
  856. void AGAScrollBarMA::HiliteState(Boolean state, Boolean redraw)
  857.     {
  858.     // Suppress Control Manager scroll bar drawing.
  859.     }
  860.  
  861. void AGAScrollBarMA::Hilite()
  862.     {
  863.     // Suppress Control Manager scroll bar drawing.
  864.     }
  865.  
  866. void AGAScrollBarMA::DimState(Boolean state, Boolean redraw)
  867.     {
  868.     // Set the AGAObject's enable state.
  869.  
  870.     if (mAGAObject != NULL)
  871.         {
  872.         Boolean    wantRedraw = redraw && this->Focus();
  873.  
  874.         mAGAObject->SetEnable(!state, wantRedraw);
  875.         }
  876.     }
  877.  
  878. void AGAScrollBarMA::Dim()
  879.     {
  880.     // Set the AGAObject's enable state, with immediate redraw.
  881.  
  882.     if (mAGAObject != NULL)
  883.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  884.     }
  885.  
  886. void AGAScrollBarMA::Activate(Boolean entering)
  887.     {
  888.     // Set the AGAScrollBar's activated state.
  889.  
  890.     if (mAGAObject != NULL)
  891.         mAGAObject->Activate(entering, this->Focus());
  892.     }
  893.  
  894. void AGAScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw)
  895.     {
  896.     // Set the AGAScrollBar's limit.
  897.     
  898.     Inherited::SetLongMax(itsMax, kDontRedraw);
  899.  
  900.     if (mAGAObject != NULL)
  901.         {
  902.         SInt32    itsMin;
  903.         SInt32    itsMax;
  904.         Boolean    wantRedraw = redraw && this->Focus();
  905.  
  906.         mAGAObject->GetRange(&itsMin, &itsMax);
  907.         mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw);
  908.         }
  909.     }
  910.  
  911. void AGAScrollBarMA::RealAGANotifier(AGATrackingIndicator* theIndicator, SInt32 dataValue, void* userData)
  912.     {
  913.     // This is a static function. Cast the user data to get
  914.     // the AGAScrollBarMA object, have it handle the notification.
  915.  
  916.     ((AGAScrollBarMA*) userData)->HandleNotification(dataValue);
  917.     }
  918.  
  919. //
  920. // AGAScrollerScrollBarMA ----------------------------------------------------
  921. //
  922.  
  923. #undef Inherited
  924. #define Inherited TScrollerScrollBar
  925.  
  926. MA_DEFINE_CLASS_M1(AGAScrollerScrollBarMA, Inherited);
  927.  
  928. AGAScrollerScrollBarMA::AGAScrollerScrollBarMA()
  929.     {
  930.     mNotificationRoutine = NULL;
  931.     mAGAObject = NULL;
  932.     }
  933.  
  934. AGAScrollerScrollBarMA::~AGAScrollerScrollBarMA()
  935.     {
  936.     // Delete AGA object if we successfully allocated it.
  937.  
  938.     if (mAGAObject != NULL)
  939.         delete mAGAObject;
  940.     }
  941.  
  942. void AGAScrollerScrollBarMA::IAGAScrollerScrollBarMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsMax, TScroller* itsScroller)
  943.     {
  944.     this->IScrollerScrollBar(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsDirection, itsMax, itsScroller);
  945.  
  946.     this->CreateAGAObject();
  947.     }
  948.  
  949. void AGAScrollerScrollBarMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  950.     {
  951.     // Save the notification routine fn pointer and user data
  952.     // for notification handling.
  953.  
  954.     mNotificationRoutine = notificationRoutine;
  955.     mUserData = userData;
  956.     }
  957.  
  958. void AGAScrollerScrollBarMA::HandleNotification(SInt32 dataValue)
  959.     {
  960.     // Scroll our scrollers and call the installed notification
  961.     // function.
  962.  
  963.     CObjectIterator iter(fScrollers);
  964.  
  965.     for (TScroller* aScroller = (TScroller*) iter.FirstObject(); iter.More(); aScroller = (TScroller*) iter.NextObject())
  966.         (void) aScroller->ScrollRelative(fDirection, dataValue);
  967.  
  968.     if (mNotificationRoutine != NULL)
  969.         (*mNotificationRoutine)(this, dataValue, mUserData);
  970.  
  971.     (void) this->Focus();
  972.     }
  973.  
  974. void AGAScrollerScrollBarMA::DoPostCreate(TDocument* itsDocument)
  975.     {
  976.     // Create and set up the AGAObject.
  977.  
  978.     Inherited::DoPostCreate(itsDocument);
  979.     
  980.     this->CreateAGAObject();
  981.     }
  982.  
  983. void AGAScrollerScrollBarMA::CreateAGAObject()
  984.     {
  985.     // Instantiate the particular AGAObject subclass.
  986.  
  987.     (void) this->SetCMgrVisibility(FALSE);
  988.  
  989.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  990.     CRect    bounds;
  991.     
  992.     this->ViewToQDRect(viewRect, bounds);
  993.  
  994.     FailNIL(mAGAObject = new AGAScrollBar(bounds, this->GetLongMin(), this->GetLongMax(), this->GetLongVal()));
  995.     
  996.     mAGAObject->InstallNotificationRoutine(AGAScrollerScrollBarMA::RealAGANotifier, this);
  997.  
  998.     if (! fEnabled)
  999.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1000.  
  1001.     this->UpdateScrollAmounts();
  1002.     }
  1003.  
  1004. void AGAScrollerScrollBarMA::Draw(const VRect& area)
  1005.     {
  1006.     // Let the AGAObject draw itself.
  1007.  
  1008.     if (mAGAObject != NULL)
  1009.         mAGAObject->DrawObject();
  1010.     }
  1011.  
  1012. void AGAScrollerScrollBarMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1013.     {
  1014.     // Let the MacApp stuff relocate and recalculate,
  1015.     // then resynchronize the AGAScrollBar to the scrollers.
  1016.  
  1017.     Inherited::SetFrame(newFrame, invalidate);
  1018.     
  1019.     this->UpdateScrollAmounts();
  1020.     
  1021.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1022.     }
  1023.  
  1024. void AGAScrollerScrollBarMA::AttachScroller(TScroller* itsScroller)
  1025.     {
  1026.     // Synchronize the AGAScrollBar to the supplied scroller.
  1027.  
  1028.     Inherited::AttachScroller(itsScroller);
  1029.     
  1030.     this->UpdateScrollAmounts();
  1031.     }
  1032.  
  1033. void AGAScrollerScrollBarMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  1034.     {
  1035.     // Catch all value changes here and synchronize the
  1036.     // AGAScrollBar accordingly.
  1037.  
  1038.     Inherited::SetLongVal(itsVal, redraw);
  1039.     
  1040.     if (mAGAObject != NULL)
  1041.         {
  1042.         Boolean    wantRedraw = redraw && this->Focus();
  1043.  
  1044.         mAGAObject->SetValue(itsVal, wantRedraw);
  1045.         }
  1046.     }
  1047.  
  1048. void AGAScrollerScrollBarMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  1049.     {
  1050.     // Let the AGAObject track the mouse. Don't call HandleEvent;
  1051.     // it has already been handled through HandleNotification.
  1052.  
  1053.     (void) mAGAObject->TrackMouse(this->ViewToQDPt(theMouse));
  1054.     }
  1055.  
  1056. void AGAScrollerScrollBarMA::HiliteState(Boolean state, Boolean redraw)
  1057.     {
  1058.     // Suppress Control Manager scroll bar drawing.
  1059.     }
  1060.  
  1061. void AGAScrollerScrollBarMA::Hilite()
  1062.     {
  1063.     // Suppress Control Manager scroll bar drawing.
  1064.     }
  1065.  
  1066. void AGAScrollerScrollBarMA::DimState(Boolean state, Boolean redraw)
  1067.     {
  1068.     // Set the AGAObject's enable state.
  1069.  
  1070.     if (mAGAObject != NULL)
  1071.         {
  1072.         Boolean    wantRedraw = redraw && this->Focus();
  1073.  
  1074.         mAGAObject->SetEnable(!state, wantRedraw);
  1075.         }
  1076.     }
  1077.  
  1078. void AGAScrollerScrollBarMA::Dim()
  1079.     {
  1080.     // Set the AGAObject's enable state, with immediate redraw.
  1081.  
  1082.     if (mAGAObject != NULL)
  1083.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1084.     }
  1085.  
  1086. void AGAScrollerScrollBarMA::Activate(Boolean entering)
  1087.     {
  1088.     // Set the AGAScrollBar's activated state.
  1089.  
  1090.     if (mAGAObject != NULL)
  1091.         mAGAObject->Activate(entering, this->Focus());
  1092.     }
  1093.  
  1094. void AGAScrollerScrollBarMA::SetLongMax(VCoordinate itsMax, Boolean redraw)
  1095.     {
  1096.     // Set the AGAScrollBar's limit.
  1097.     
  1098.     Inherited::SetLongMax(itsMax, kDontRedraw);
  1099.  
  1100.     if (mAGAObject != NULL)
  1101.         {
  1102.         SInt32    itsMin;
  1103.         SInt32    itsMax;
  1104.         Boolean    wantRedraw = redraw && this->Focus();
  1105.  
  1106.         mAGAObject->GetRange(&itsMin, &itsMax);
  1107.         mAGAObject->SetRange(itsMin, this->GetLongMax(), wantRedraw);
  1108.         }
  1109.     }
  1110.  
  1111. void AGAScrollerScrollBarMA::UpdateScrollAmounts()
  1112.     {
  1113.     // Synchronize the AGAScrollBar to reflect the scroller
  1114.     // state.
  1115.  
  1116.     if ((mAGAObject != NULL) && (fScrollers->GetSize() > 0))
  1117.         {
  1118.         TScroller*    aScroller = (TScroller*) fScrollers->At(1);
  1119.         VCoordinate    maxTranslation = aScroller->fMaxTranslation[fDirection];
  1120.         VCoordinate    viewSize = aScroller->fSize[fDirection];
  1121.         VCoordinate    singleStepSize = aScroller->fScrollUnit[fDirection];
  1122.         VCoordinate    pageStepSize = Max(0, viewSize - singleStepSize);
  1123.         VCoordinate    pageSize = maxTranslation * (((float) (Max(0, viewSize - singleStepSize))) / ((float) (viewSize + maxTranslation)));
  1124.  
  1125.         (void) this->Focus();
  1126.  
  1127.         mAGAObject->SetRange(0, maxTranslation, kDontRedraw);
  1128.         mAGAObject->SetPageSize(pageSize, kRedraw);
  1129.         mAGAObject->SetStepSizes(singleStepSize, pageStepSize);
  1130.         }
  1131.     }
  1132.  
  1133. void AGAScrollerScrollBarMA::RealAGANotifier(AGATrackingIndicator* theIndicator, SInt32 dataValue, void* userData)
  1134.     {
  1135.     // This is a static function. Cast the user data to get
  1136.     // the AGAScrollerScrollBarMA object, have it handle the notification.
  1137.  
  1138.     ((AGAScrollerScrollBarMA*) userData)->HandleNotification(dataValue);
  1139.     }
  1140.  
  1141. //
  1142. // AGASliderMA ----------------------------------------------------
  1143. //
  1144.  
  1145. #undef Inherited
  1146. #define Inherited TControl
  1147.  
  1148. MA_DEFINE_CLASS_M1(AGASliderMA, Inherited);
  1149.  
  1150. AGASliderMA::AGASliderMA()
  1151.     {
  1152.     mAGAObject = NULL;
  1153.     }
  1154.  
  1155. AGASliderMA::~AGASliderMA()
  1156.     {
  1157.     // Delete AGA object if we successfully allocated it.
  1158.  
  1159.     if (mAGAObject != NULL)
  1160.         delete mAGAObject;
  1161.     }
  1162.  
  1163. void AGASliderMA::IAGASliderMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  1164.     {
  1165.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  1166.  
  1167.     this->CreateAGAObject();
  1168.     }
  1169.  
  1170. void AGASliderMA::DoPostCreate(TDocument* itsDocument)
  1171.     {
  1172.     // Create and set up the AGAObject.
  1173.  
  1174.     Inherited::DoPostCreate(itsDocument);
  1175.     
  1176.     this->CreateAGAObject();
  1177.     }
  1178.  
  1179. void AGASliderMA::CreateAGAObject()
  1180.     {
  1181.     // Instantiate the particular AGAObject subclass.
  1182.  
  1183.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1184.     CRect    bounds;
  1185.     
  1186.     this->ViewToQDRect(viewRect, bounds);
  1187.  
  1188.     FailNIL(mAGAObject = new AGASlider(bounds, 0, 1, 0, AGATextStyle(fTextStyle), fUserArea));
  1189.  
  1190.     if (! fEnabled)
  1191.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1192.     }
  1193.  
  1194. void AGASliderMA::Draw(const VRect& area)
  1195.     {
  1196.     // Let the AGAObject draw itself.
  1197.  
  1198.     if (mAGAObject != NULL)
  1199.         mAGAObject->DrawObject();
  1200.     }
  1201.  
  1202. void AGASliderMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1203.     {
  1204.     // Let the MacApp and AGA objects update their locations.
  1205.  
  1206.     Inherited::SetFrame(newFrame, invalidate);
  1207.     
  1208.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1209.     }
  1210.  
  1211. void AGASliderMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  1212.     {
  1213.     // Let the AGAObject track the mouse; if tracking succeeds
  1214.     // handle our event number.
  1215.  
  1216.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1217.         this->HandleEvent(fEventNumber, this, NULL);
  1218.     }
  1219.  
  1220. void AGASliderMA::DimState(Boolean state, Boolean redraw)
  1221.     {
  1222.     // Set the AGAObject's enable state.
  1223.  
  1224.     if (mAGAObject != NULL)
  1225.         {
  1226.         Boolean    wantRedraw = redraw && this->Focus();
  1227.  
  1228.         mAGAObject->SetEnable(!state, wantRedraw);
  1229.         }
  1230.     }
  1231.  
  1232. void AGASliderMA::Dim()
  1233.     {
  1234.     // Set the AGAObject's enable state, with immediate redraw.
  1235.  
  1236.     if (mAGAObject != NULL)
  1237.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1238.     }
  1239.  
  1240. //
  1241. // AGABackgroundAdornerMA ----------------------------------------------------
  1242. //
  1243.  
  1244. #undef Inherited
  1245. #define Inherited TAdorner
  1246.  
  1247. MA_DEFINE_CLASS_M1(AGABackgroundAdornerMA, Inherited);
  1248.  
  1249. AGABackgroundAdornerMA::AGABackgroundAdornerMA()
  1250.     {
  1251.     // Construct with color indexes for modeless gray background.
  1252.     // The edge values are slightly different when the window is
  1253.     // inactive.
  1254.  
  1255.     mRampIndexes[kBGFill] = r2;
  1256.     mRampIndexes[kBGActiveLight] = rW;
  1257.     mRampIndexes[kBGActiveShadow] = r5;
  1258.     mRampIndexes[kBGInactiveLight] = r1;
  1259.     mRampIndexes[kBGInactiveShadow] = r4;
  1260.     }
  1261.  
  1262. void AGABackgroundAdornerMA::DoHighlightSelection(TView* itsView, const VRect& area, HLState fromHL, HLState toHL)
  1263.     {
  1264.     // Draw in the specified active/inactive state.
  1265.  
  1266.     this->DrawBackground(itsView, area, FALSE, (toHL == hlOn));
  1267.     }
  1268.  
  1269. void AGABackgroundAdornerMA::Draw(TView* itsView, const VRect& area)
  1270.     {
  1271.     // Draw in active state.
  1272.  
  1273.     this->DrawBackground(itsView, area, TRUE, itsView->IsActive());
  1274.     }
  1275.  
  1276. void AGABackgroundAdornerMA::ViewChangedFrame(TView* itsView, const VRect& oldFrame, const VRect& newFrame, Boolean    invalidate)
  1277.     {
  1278.     // Make sure we invalidate the edges that will need to be
  1279.     // redrawn with the background edge pixel color.
  1280.     // Note that oldFrame & newFrame are in global coordinates.
  1281.  
  1282.     VRect    rectToInvalidate;
  1283.     VPoint    sizeDelta(newFrame.GetLength(hSel) - oldFrame.GetLength(hSel),
  1284.                     newFrame.GetLength(vSel) - oldFrame.GetLength(vSel));
  1285.     
  1286.     if (sizeDelta.h != 0)
  1287.         {
  1288.         if (sizeDelta.h > 0)
  1289.             rectToInvalidate = oldFrame;
  1290.         else    // sizeDelta.h < 0
  1291.             rectToInvalidate = newFrame;
  1292.  
  1293.         rectToInvalidate.left = rectToInvalidate.right - 1;
  1294.         itsView->SuperToLocalVRect(rectToInvalidate);
  1295.         itsView->InvalidateVRect(rectToInvalidate);
  1296.         }
  1297.     
  1298.     if (sizeDelta.v != 0)
  1299.         {
  1300.         if (sizeDelta.v > 0)
  1301.             rectToInvalidate = oldFrame;
  1302.         else    // sizeDelta.v < 0
  1303.             rectToInvalidate = newFrame;
  1304.  
  1305.         rectToInvalidate.top = rectToInvalidate.bottom - 1;
  1306.         itsView->SuperToLocalVRect(rectToInvalidate);
  1307.         itsView->InvalidateVRect(rectToInvalidate);
  1308.         }
  1309.     
  1310.     if (this->HasGrowBox(itsView))
  1311.         {
  1312.         rectToInvalidate = oldFrame;
  1313.         rectToInvalidate.left = rectToInvalidate.right - 16;
  1314.         rectToInvalidate.top = rectToInvalidate.bottom - 16;
  1315.         itsView->SuperToLocalVRect(rectToInvalidate);
  1316.         itsView->InvalidateVRect(rectToInvalidate);
  1317.  
  1318.         rectToInvalidate = newFrame;
  1319.         rectToInvalidate.left = rectToInvalidate.right - 16;
  1320.         rectToInvalidate.top = rectToInvalidate.bottom - 16;
  1321.         itsView->SuperToLocalVRect(rectToInvalidate);
  1322.         itsView->InvalidateVRect(rectToInvalidate);
  1323.         }
  1324.     }
  1325.  
  1326. void AGABackgroundAdornerMA::DrawBackground(TView* itsView, const VRect& area, Boolean fill, Boolean active)
  1327.     {
  1328.     CRect    qdArea;
  1329.     
  1330.     itsView->GetQDExtent(qdArea);
  1331.     
  1332.     AGABackgroundPaint(qdArea, fill, kIsNotModal, active, this->HasGrowBox(itsView));
  1333.     }
  1334.  
  1335. Boolean AGABackgroundAdornerMA::HasGrowBox(TView* itsView)
  1336.     {
  1337.     if (MA_MEMBER(itsView, TWindow))
  1338.         return ((TWindow*) itsView)->fIsResizable;
  1339.     else
  1340.         return FALSE;
  1341.     }
  1342.  
  1343.  
  1344. //
  1345. // AGAModalBackgroundAdornerMA ----------------------------------------------------
  1346. //
  1347.  
  1348. #undef Inherited
  1349. #define Inherited AGABackgroundAdornerMA
  1350.  
  1351. MA_DEFINE_CLASS_M1(AGAModalBackgroundAdornerMA, Inherited);
  1352.  
  1353. AGAModalBackgroundAdornerMA::AGAModalBackgroundAdornerMA()
  1354.     {
  1355.     // Construct with color indexes for modal gray background.
  1356.  
  1357.     mRampIndexes[kBGFill] = r2;
  1358.     mRampIndexes[kBGActiveLight] = rW;
  1359.     mRampIndexes[kBGActiveShadow] = r6;
  1360.     mRampIndexes[kBGInactiveLight] = r1;
  1361.     mRampIndexes[kBGInactiveShadow] = r4;
  1362.     }
  1363.  
  1364. void AGAModalBackgroundAdornerMA::DrawBackground(TView* itsView, const VRect& area, Boolean fill, Boolean active)
  1365.     {
  1366.     CRect    qdArea;
  1367.     
  1368.     itsView->GetQDExtent(qdArea);
  1369.     
  1370.     AGABackgroundPaint(qdArea, fill, kIsModal, active, this->HasGrowBox(itsView));
  1371.     }
  1372.  
  1373. //
  1374. // AGAWhiteBackgroundAdornerMA ----------------------------------------------------
  1375. //
  1376.  
  1377. #undef Inherited
  1378. #define Inherited TAdorner
  1379.  
  1380. MA_DEFINE_CLASS_M1(AGAWhiteBackgroundAdornerMA, Inherited);
  1381.  
  1382. void AGAWhiteBackgroundAdornerMA::Draw(TView* itsView, const VRect& area)
  1383.     {
  1384.     // Draw the background in white, inset to avoid the border
  1385.     // frame pixels.
  1386.  
  1387.     CRect    qdArea;
  1388.     
  1389.     itsView->GetQDExtent(qdArea);
  1390.     
  1391.     ::RGBForeColor(&gAGARamp[rW]);
  1392.     ::InsetRect(qdArea, 2, 2);
  1393.     ::PaintRect(qdArea);
  1394.  
  1395.     ::RGBForeColor(&gAGARamp[rB]);
  1396.     }
  1397.  
  1398. //
  1399. // AGABorderFrameAdornerMA ----------------------------------------------------
  1400. //
  1401.  
  1402. #undef Inherited
  1403. #define Inherited TAdorner
  1404.  
  1405. MA_DEFINE_CLASS_M1(AGABorderFrameAdornerMA, Inherited);
  1406.  
  1407. void AGABorderFrameAdornerMA::Draw(TView* itsView, const VRect& area)
  1408.     {
  1409.     // Draw the frame with shading outside.
  1410.  
  1411.     enum { TL, Frame, BR, kNumColors };
  1412.  
  1413.     UInt8    colorIndex[kNumColors];
  1414.     CRect    qdArea;
  1415.     
  1416.     itsView->GetQDExtent(qdArea);
  1417.     
  1418.     GDIterator    iter;
  1419.     Boolean        deep;
  1420.  
  1421.     while (iter.More(deep))
  1422.         {
  1423.         if (deep)
  1424.             {
  1425.             if (itsView->IsEnabled())
  1426.                 {
  1427.                 colorIndex[TL] = r5;
  1428.                 colorIndex[Frame] = rB;
  1429.                 colorIndex[BR] = rW;
  1430.                 }
  1431.             else
  1432.                 {
  1433.                 colorIndex[TL] = r4;
  1434.                 colorIndex[Frame] = r10;
  1435.                 colorIndex[BR] = r1;
  1436.                 }
  1437.             }
  1438.         else    // 1-bit
  1439.             {
  1440.             colorIndex[Frame] = rB;
  1441.             
  1442.             if (! itsView->IsEnabled())
  1443.                 ::PenPat(&qd.gray);
  1444.             }
  1445.         
  1446.         ::RGBForeColor(&gAGARamp[colorIndex[Frame]]);
  1447.         ::InsetRect(qdArea, 1, 1);
  1448.         ::FrameRect(qdArea);
  1449.         ::InsetRect(qdArea, -1, -1);
  1450.         
  1451.         if (deep)
  1452.             {
  1453.             ::RGBForeColor(&gAGARamp[colorIndex[TL]]);
  1454.             ::MoveTo(qdArea.left, qdArea.bottom - 2);
  1455.             ::LineTo(qdArea.left, qdArea.top);
  1456.             ::LineTo(qdArea.right - 2, qdArea.top);
  1457.             
  1458.             ::RGBForeColor(&gAGARamp[colorIndex[BR]]);
  1459.             ::MoveTo(qdArea.left + 1, qdArea.bottom - 1);
  1460.             ::LineTo(qdArea.right - 1, qdArea.bottom - 1);
  1461.             ::LineTo(qdArea.right - 1, qdArea.top + 1);
  1462.             }
  1463.         else if (! itsView->IsEnabled())
  1464.             ::PenPat(&qd.black);
  1465.         }
  1466.  
  1467.     ::RGBForeColor(&gAGARamp[rB]);
  1468.     }
  1469.  
  1470. //
  1471. // AGAPopupMA ----------------------------------------------------
  1472. //
  1473.  
  1474. #undef Inherited
  1475. #define Inherited TPopup
  1476.  
  1477. MA_DEFINE_CLASS_M1(AGAPopupMA, Inherited);
  1478.  
  1479. AGAPopupMA::AGAPopupMA()
  1480.     {
  1481.     mAGAObject = NULL;
  1482.     }
  1483.  
  1484. AGAPopupMA::~AGAPopupMA()
  1485.     {
  1486.     // Delete AGA object if we successfully allocated it.
  1487.  
  1488.     if (mAGAObject != NULL)
  1489.         delete mAGAObject;
  1490.     }
  1491.  
  1492. void AGAPopupMA::IAGAPopupMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, short itsMenuID, short itsCurrentItem, short itsItemOffset, short itsStrListID, short itsIndex, short itsStyle, short itsJust, Boolean useAddResMenu, ResType useAddResMenuResType, const TextStyle& itsTextStyle)
  1493.     {
  1494.     this->IPopup(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsMenuID, itsCurrentItem, itsItemOffset, itsStrListID, itsIndex, itsStyle, itsJust, useAddResMenu, useAddResMenuResType, itsTextStyle);
  1495.  
  1496.     this->CreateAGAObject();
  1497.     }
  1498.  
  1499. void AGAPopupMA::DoPostCreate(TDocument* itsDocument)
  1500.     {
  1501.     // Create and set up the AGAObject.
  1502.  
  1503.     Inherited::DoPostCreate(itsDocument);
  1504.     
  1505.     this->CreateAGAObject();
  1506.     }
  1507.  
  1508. void AGAPopupMA::CreateAGAObject()
  1509.     {
  1510.     // Instantiate the particular AGAObject subclass.
  1511.  
  1512.     (void) this->SetCMgrVisibility(FALSE);
  1513.  
  1514.     AGAPopupMenu::WidthAdjust    widthAdjust;
  1515.     
  1516.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1517.     CRect    bounds;
  1518.     CStr255    viewTitle;
  1519.     
  1520.     this->ViewToQDRect(viewRect, bounds);
  1521.     this->GetText(viewTitle);
  1522.  
  1523.     if (fSizeDeterminer[hSel] == sizeFixed)
  1524.         widthAdjust = AGAPopupMenu::kFixedWidth;
  1525.     else
  1526.         widthAdjust = AGAPopupMenu::kSystemMDEFAdjustment;
  1527.  
  1528.     FailNIL(mAGAObject = new AGAPopupMenu(bounds, fItemOffset, viewTitle, fTitleJust, AGATextStyle(fTextStyle), widthAdjust, this->GetMenuRef(), AGAPopupMenu::kDontDispose));
  1529.  
  1530.     if (! fEnabled)
  1531.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1532.     }
  1533.  
  1534. void AGAPopupMA::Draw(const VRect& area)
  1535.     {
  1536.     // Let the AGAObject draw itself.
  1537.  
  1538.     if (mAGAObject != NULL)
  1539.         mAGAObject->DrawObject();
  1540.     }
  1541.  
  1542. void AGAPopupMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1543.     {
  1544.     // Let the MacApp and AGA objects update their locations.
  1545.  
  1546.     Inherited::SetFrame(newFrame, invalidate);
  1547.     
  1548.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1549.     }
  1550.  
  1551. void AGAPopupMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  1552.     {
  1553.     // Let the AGAObject track the mouse; if tracking succeeds
  1554.     // handle our event number.
  1555.  
  1556.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1557.         this->HandleEvent(fEventNumber, this, NULL);
  1558.     }
  1559.  
  1560. void AGAPopupMA::DimState(Boolean state, Boolean redraw)
  1561.     {
  1562.     // Set the AGAObject's enable state.
  1563.  
  1564.     if (mAGAObject != NULL)
  1565.         {
  1566.         Boolean    wantRedraw = redraw && this->Focus();
  1567.  
  1568.         mAGAObject->SetEnable(!state, wantRedraw);
  1569.         }
  1570.     }
  1571.  
  1572. void AGAPopupMA::Dim()
  1573.     {
  1574.     // Set the AGAObject's enable state, with immediate redraw.
  1575.  
  1576.     if (mAGAObject != NULL)
  1577.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1578.     }
  1579.  
  1580. void AGAPopupMA::AttachMenuRef(MenuRef itsMenuRef)
  1581.     {
  1582.     //
  1583.     // Since TPopup owns the menu, it will do the disposal.
  1584.     //
  1585.     
  1586.     Inherited::AttachMenuRef(itsMenuRef);
  1587.  
  1588.     if (mAGAObject != NULL)
  1589.         mAGAObject->SetMenuRef(itsMenuRef, AGAPopupMenu::kDontDispose);
  1590.     }
  1591.  
  1592. void AGAPopupMA::SetText(const CStr255& title, Boolean redraw)
  1593.     {
  1594.     Inherited::SetText(title, redraw);
  1595.     }
  1596.  
  1597. void AGAPopupMA::SetLongVal(VCoordinate itsVal, Boolean redraw)
  1598.     {
  1599.     // Catch all value changes here and synchronize the
  1600.     // AGAPopupMenu accordingly.
  1601.  
  1602.     if (mAGAObject != NULL)
  1603.         mAGAObject->SetCurrentItemNo((SInt16) itsVal, redraw);
  1604.     else
  1605.         Inherited::SetLongVal(itsVal, redraw);
  1606.     }
  1607.  
  1608. SInt16 AGAPopupMA::GetVal()
  1609.     {
  1610.     // Return the currently selected item number.
  1611.  
  1612.     if (mAGAObject != NULL)
  1613.         return mAGAObject->GetCurrentItemNo();
  1614.     else
  1615.         return Inherited::GetVal();
  1616.     }
  1617.  
  1618. //
  1619. // AGAStaticTextMA ----------------------------------------------------
  1620. //
  1621.  
  1622. #undef Inherited
  1623. #define Inherited TStaticText
  1624.  
  1625. MA_DEFINE_CLASS_M1(AGAStaticTextMA, Inherited);
  1626.  
  1627. AGAStaticTextMA::AGAStaticTextMA()
  1628.     {
  1629.     mAGAObject = NULL;
  1630.     }
  1631.  
  1632. AGAStaticTextMA::~AGAStaticTextMA()
  1633.     {
  1634.     // Delete AGA object if we successfully allocated it.
  1635.  
  1636.     if (mAGAObject != NULL)
  1637.         delete mAGAObject;
  1638.     }
  1639.  
  1640. void AGAStaticTextMA::IAGAStaticTextMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  1641.     {
  1642.     this->IStaticText(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  1643.  
  1644.     this->CreateAGAObject();
  1645.     }
  1646.  
  1647. void AGAStaticTextMA::DoPostCreate(TDocument* itsDocument)
  1648.     {
  1649.     // Create and set up the AGAObject.
  1650.  
  1651.     Inherited::DoPostCreate(itsDocument);
  1652.     
  1653.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1654.     CRect    qdRect;
  1655.     
  1656.     this->ViewToQDRect(viewRect, qdRect);
  1657.  
  1658.     this->CreateAGAObject();
  1659.     }
  1660.  
  1661. void AGAStaticTextMA::CreateAGAObject()
  1662.     {
  1663.     // Instantiate the particular AGAObject subclass.
  1664.  
  1665.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1666.     CRect    bounds;
  1667.     CStr255    viewTitle;
  1668.     
  1669.     this->ViewToQDRect(viewRect, bounds);
  1670.     this->GetText(viewTitle);
  1671.  
  1672.     FailNIL(mAGAObject = new AGAStaticText(bounds, AGATextStyle(fTextStyle), fJust, viewTitle));
  1673.  
  1674.     if (! fEnabled)
  1675.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1676.     }
  1677.  
  1678. void AGAStaticTextMA::SetText(const CStr255& theText, Boolean redraw)
  1679.     {
  1680.     // Change the current text in TStaticText and in
  1681.     // the AGAStaticText. Do NOT let TStaticText redraw,
  1682.     // because it erases to white.
  1683.  
  1684.     Inherited::SetText(theText, kDontRedraw);
  1685.  
  1686.     if (mAGAObject != NULL)
  1687.         {
  1688.         Str255    textString;
  1689.         Boolean    wantRedraw = redraw && this->Focus();
  1690.  
  1691.         PLstrcpy(textString, theText);
  1692.         mAGAObject->SetTitle(textString, wantRedraw);
  1693.         }
  1694.     }
  1695.  
  1696. void AGAStaticTextMA::DimState(Boolean state, Boolean redraw)
  1697.     {
  1698.     // Set the AGAObject's enable state.
  1699.  
  1700.     if (mAGAObject != NULL)
  1701.         {
  1702.         Boolean    wantRedraw = redraw && this->Focus();
  1703.  
  1704.         mAGAObject->SetEnable(!state, wantRedraw);
  1705.         }
  1706.     }
  1707.  
  1708. void AGAStaticTextMA::Dim()
  1709.     {
  1710.     // Set the AGAObject's enable state, with immediate redraw.
  1711.  
  1712.     if (mAGAObject != NULL)
  1713.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1714.     }
  1715.  
  1716. void AGAStaticTextMA::Draw(const VRect& area)
  1717.     {
  1718.     // Let the AGAObject draw itself.
  1719.  
  1720.     if (mAGAObject != NULL)
  1721.         mAGAObject->DrawObject();
  1722.     }
  1723.  
  1724. void AGAStaticTextMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1725.     {
  1726.     // Let the MacApp and AGA objects update their locations.
  1727.  
  1728.     Inherited::SetFrame(newFrame, invalidate);
  1729.     
  1730.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1731.     }
  1732.  
  1733. //
  1734. // AGALittleArrowsMA ----------------------------------------------------
  1735. //
  1736.  
  1737. #undef Inherited
  1738. #define Inherited TControl
  1739.  
  1740. MA_DEFINE_CLASS_M1(AGALittleArrowsMA, Inherited);
  1741.  
  1742. AGALittleArrowsMA::AGALittleArrowsMA()
  1743.     {
  1744.     mNotificationRoutine = NULL;
  1745.     mAGAObject = NULL;
  1746.     mLinkedNumberText = NULL;
  1747.     }
  1748.  
  1749. AGALittleArrowsMA::~AGALittleArrowsMA()
  1750.     {
  1751.     // Delete AGA object if we successfully allocated it.
  1752.  
  1753.     if (mAGAObject != NULL)
  1754.         delete mAGAObject;
  1755.     }
  1756.  
  1757. void AGALittleArrowsMA::IAGALittleArrowsMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  1758.     {
  1759.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  1760.  
  1761.     this->CreateAGAObject();
  1762.     }
  1763.  
  1764. void AGALittleArrowsMA::InstallNotificationRoutine(AGANotifyMAPtr notificationRoutine, void* userData)
  1765.     {
  1766.     // Save the notification routine fn pointer and user data
  1767.     // for notification handling.
  1768.  
  1769.     mNotificationRoutine = notificationRoutine;
  1770.     mUserData = userData;
  1771.     }
  1772.  
  1773. void AGALittleArrowsMA::HandleNotification(SInt32 deltaValue)
  1774.     {
  1775.     // Update the linked TNumberText, if any, call the
  1776.     // installed notification function, and propagate our
  1777.     // event number.
  1778.  
  1779.     if (mLinkedNumberText != NULL)
  1780.         mLinkedNumberText->SetValue(mLinkedNumberText->GetValue() + deltaValue, kRedraw);
  1781.  
  1782.     if (mNotificationRoutine != NULL)
  1783.         (*mNotificationRoutine)(this, deltaValue, mUserData);
  1784.     
  1785.     this->HandleEvent(fEventNumber, this, NULL);
  1786.  
  1787.     (void) this->Focus();
  1788.     }
  1789.  
  1790. void AGALittleArrowsMA::DoPostCreate(TDocument* itsDocument)
  1791.     {
  1792.     // Create and set up the AGAObject.
  1793.  
  1794.     Inherited::DoPostCreate(itsDocument);
  1795.     
  1796.     this->CreateAGAObject();
  1797.     }
  1798.  
  1799. void AGALittleArrowsMA::CreateAGAObject()
  1800.     {
  1801.     // Instantiate the particular AGAObject subclass.
  1802.  
  1803.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1804.     CRect    bounds;
  1805.     
  1806.     this->ViewToQDRect(viewRect, bounds);
  1807.  
  1808.     FailNIL(mAGAObject = new AGALittleArrows(bounds));
  1809.     
  1810.     mAGAObject->InstallNotificationRoutine(AGALittleArrowsMA::RealAGANotifier, this);
  1811.  
  1812.     if (! fEnabled)
  1813.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1814.  
  1815.     if (fUserArea != 0)
  1816.         {
  1817.         mLinkedNumberText = (TNumberText*) this->GetWindow()->FindSubView(fUserArea);
  1818.         if (mLinkedNumberText != NULL)
  1819.             if (! MA_MEMBER(mLinkedNumberText, TNumberText))
  1820.                 mLinkedNumberText = NULL;
  1821.         }
  1822.     }
  1823.  
  1824. void AGALittleArrowsMA::Draw(const VRect& area)
  1825.     {
  1826.     // Let the AGAObject draw itself.
  1827.  
  1828.     if (mAGAObject != NULL)
  1829.         mAGAObject->DrawObject();
  1830.     }
  1831.  
  1832. void AGALittleArrowsMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1833.     {
  1834.     // Let the MacApp and AGA objects update their locations.
  1835.  
  1836.     Inherited::SetFrame(newFrame, invalidate);
  1837.     
  1838.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1839.     }
  1840.  
  1841. void AGALittleArrowsMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  1842.     {
  1843.     // Let the AGAObject track the mouse; if tracking succeeds
  1844.     // handle our event number.
  1845.  
  1846.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1847.         this->HandleEvent(fEventNumber, this, NULL);
  1848.     }
  1849.  
  1850. void AGALittleArrowsMA::DimState(Boolean state, Boolean redraw)
  1851.     {
  1852.     // Set the AGAObject's enable state.
  1853.  
  1854.     if (mAGAObject != NULL)
  1855.         {
  1856.         Boolean    wantRedraw = redraw && this->Focus();
  1857.  
  1858.         mAGAObject->SetEnable(!state, wantRedraw);
  1859.         }
  1860.     }
  1861.  
  1862. void AGALittleArrowsMA::Dim()
  1863.     {
  1864.     // Set the AGAObject's enable state, with immediate redraw.
  1865.  
  1866.     if (mAGAObject != NULL)
  1867.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1868.     }
  1869.  
  1870. void AGALittleArrowsMA::RealAGANotifier(AGALittleArrows* theAGAObject, SInt32 deltaValue, void* userData)
  1871.     {
  1872.     // This is a static function. Cast the user data to get
  1873.     // the AGAScrollerScrollBarMA object, have it handle the notification.
  1874.  
  1875.     ((AGALittleArrowsMA*) userData)->HandleNotification(deltaValue);
  1876.     }
  1877.  
  1878. //
  1879. // AGADisclosureTriangleMA ----------------------------------------------------
  1880. //
  1881.  
  1882. #undef Inherited
  1883. #define Inherited TControl
  1884.  
  1885. MA_DEFINE_CLASS_M1(AGADisclosureTriangleMA, Inherited);
  1886.  
  1887. AGADisclosureTriangleMA::AGADisclosureTriangleMA()
  1888.     {
  1889.     mAGAObject = NULL;
  1890.     }
  1891.  
  1892. AGADisclosureTriangleMA::~AGADisclosureTriangleMA()
  1893.     {
  1894.     // Delete AGA object if we successfully allocated it.
  1895.  
  1896.     if (mAGAObject != NULL)
  1897.         delete mAGAObject;
  1898.     }
  1899.  
  1900. void AGADisclosureTriangleMA::IAGADisclosureTriangleMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  1901.     {
  1902.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  1903.  
  1904.     this->CreateAGAObject();
  1905.     }
  1906.  
  1907. void AGADisclosureTriangleMA::DoPostCreate(TDocument* itsDocument)
  1908.     {
  1909.     // Create and set up the AGAObject.
  1910.  
  1911.     Inherited::DoPostCreate(itsDocument);
  1912.     
  1913.     this->CreateAGAObject();
  1914.     }
  1915.  
  1916. void AGADisclosureTriangleMA::CreateAGAObject()
  1917.     {
  1918.     // Instantiate the particular AGAObject subclass.
  1919.  
  1920.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  1921.     CRect    bounds;
  1922.     
  1923.     this->ViewToQDRect(viewRect, bounds);
  1924.  
  1925.     FailNIL(mAGAObject = new AGADisclosureTriangle(bounds, AGAObject::kAutomaticState));
  1926.  
  1927.     if (! fEnabled)
  1928.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  1929.     }
  1930.  
  1931. void AGADisclosureTriangleMA::Draw(const VRect& area)
  1932.     {
  1933.     // Let the AGAObject draw itself.
  1934.  
  1935.     if (mAGAObject != NULL)
  1936.         mAGAObject->DrawObject();
  1937.     }
  1938.  
  1939. void AGADisclosureTriangleMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  1940.     {
  1941.     // Let the MacApp and AGA objects update their locations.
  1942.  
  1943.     Inherited::SetFrame(newFrame, invalidate);
  1944.     
  1945.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  1946.     }
  1947.  
  1948. void AGADisclosureTriangleMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  1949.     {
  1950.     // Let the AGAObject track the mouse; if tracking succeeds
  1951.     // handle our event number.
  1952.  
  1953.     if (mAGAObject->TrackMouse(this->ViewToQDPt(theMouse)))
  1954.         this->HandleEvent(fEventNumber, this, NULL);
  1955.     }
  1956.  
  1957. void AGADisclosureTriangleMA::DimState(Boolean state, Boolean redraw)
  1958.     {
  1959.     // Set the AGAObject's enable state.
  1960.  
  1961.     if (mAGAObject != NULL)
  1962.         {
  1963.         Boolean    wantRedraw = redraw && this->Focus();
  1964.  
  1965.         mAGAObject->SetEnable(!state, wantRedraw);
  1966.         }
  1967.     }
  1968.  
  1969. void AGADisclosureTriangleMA::Dim()
  1970.     {
  1971.     // Set the AGAObject's enable state, with immediate redraw.
  1972.  
  1973.     if (mAGAObject != NULL)
  1974.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  1975.     }
  1976.  
  1977. //
  1978. // AGAProgressIndicatorMA ----------------------------------------------------
  1979. //
  1980.  
  1981. #undef Inherited
  1982. #define Inherited TControl
  1983.  
  1984. MA_DEFINE_CLASS_M1(AGAProgressIndicatorMA, Inherited);
  1985.  
  1986. AGAProgressIndicatorMA::AGAProgressIndicatorMA()
  1987.     {
  1988.     mAGAObject = NULL;
  1989.     }
  1990.  
  1991. AGAProgressIndicatorMA::~AGAProgressIndicatorMA()
  1992.     {
  1993.     // Delete AGA object if we successfully allocated it.
  1994.  
  1995.     if (mAGAObject != NULL)
  1996.         delete mAGAObject;
  1997.     }
  1998.  
  1999. void AGAProgressIndicatorMA::IAGAProgressIndicatorMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, const TextStyle& itsTextStyle)
  2000.     {
  2001.     this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTextStyle);
  2002.  
  2003.     this->CreateAGAObject();
  2004.     }
  2005.  
  2006. void AGAProgressIndicatorMA::DoPostCreate(TDocument* itsDocument)
  2007.     {
  2008.     // Create and set up the AGAObject.
  2009.  
  2010.     Inherited::DoPostCreate(itsDocument);
  2011.     
  2012.     this->CreateAGAObject();
  2013.     }
  2014.  
  2015. void AGAProgressIndicatorMA::CreateAGAObject()
  2016.     {
  2017.     // Instantiate the particular AGAObject subclass.
  2018.  
  2019.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2020.     CRect    bounds;
  2021.     
  2022.     this->ViewToQDRect(viewRect, bounds);
  2023.  
  2024.     FailNIL(mAGAObject = new AGAProgressIndicator(bounds, 0, 100));
  2025.  
  2026.     if (! fEnabled)
  2027.         mAGAObject->SetEnable(AGAObject::kDisabled, AGAObject::kDontRedraw);
  2028.     }
  2029.  
  2030. void AGAProgressIndicatorMA::Draw(const VRect& area)
  2031.     {
  2032.     // Let the AGAObject draw itself.
  2033.  
  2034.     if (mAGAObject != NULL)
  2035.         mAGAObject->DrawObject();
  2036.     }
  2037.  
  2038. void AGAProgressIndicatorMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2039.     {
  2040.     // Let the MacApp and AGA objects update their locations.
  2041.  
  2042.     Inherited::SetFrame(newFrame, invalidate);
  2043.     
  2044.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2045.     }
  2046.  
  2047. void AGAProgressIndicatorMA::DimState(Boolean state, Boolean redraw)
  2048.     {
  2049.     // Set the AGAObject's enable state.
  2050.  
  2051.     if (mAGAObject != NULL)
  2052.         {
  2053.         Boolean    wantRedraw = redraw && this->Focus();
  2054.  
  2055.         mAGAObject->SetEnable(!state, wantRedraw);
  2056.         }
  2057.     }
  2058.  
  2059. void AGAProgressIndicatorMA::Dim()
  2060.     {
  2061.     // Set the AGAObject's enable state, with immediate redraw.
  2062.  
  2063.     if (mAGAObject != NULL)
  2064.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  2065.     }
  2066.  
  2067. //
  2068. // AGASeparatorMA ----------------------------------------------------
  2069. //
  2070.  
  2071. #undef Inherited
  2072. #define Inherited TView
  2073.  
  2074. MA_DEFINE_CLASS_M1(AGASeparatorMA, Inherited);
  2075.  
  2076. AGASeparatorMA::AGASeparatorMA()
  2077.     {
  2078.     mAGAObject = NULL;
  2079.     }
  2080.  
  2081. AGASeparatorMA::~AGASeparatorMA()
  2082.     {
  2083.     // Delete AGA object if we successfully allocated it.
  2084.  
  2085.     if (mAGAObject != NULL)
  2086.         delete mAGAObject;
  2087.     }
  2088.  
  2089. void AGASeparatorMA::IAGASeparatorMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet)
  2090.     {
  2091.     this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2092.  
  2093.     this->CreateAGAObject();
  2094.     }
  2095.  
  2096. void AGASeparatorMA::DoPostCreate(TDocument* itsDocument)
  2097.     {
  2098.     // Create and set up the AGAObject.
  2099.  
  2100.     Inherited::DoPostCreate(itsDocument);
  2101.     
  2102.     this->CreateAGAObject();
  2103.     }
  2104.  
  2105. void AGASeparatorMA::CreateAGAObject()
  2106.     {
  2107.     // Instantiate the particular AGAObject subclass.
  2108.  
  2109.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2110.     CRect    bounds;
  2111.     
  2112.     this->ViewToQDRect(viewRect, bounds);
  2113.  
  2114.     FailNIL(mAGAObject = new AGASeparator(bounds));
  2115.     }
  2116.  
  2117. void AGASeparatorMA::Draw(const VRect& area)
  2118.     {
  2119.     // Let the AGAObject draw itself.
  2120.  
  2121.     if (mAGAObject != NULL)
  2122.         mAGAObject->DrawObject();
  2123.     }
  2124.  
  2125. void AGASeparatorMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2126.     {
  2127.     // Let the MacApp and AGA objects update their locations.
  2128.  
  2129.     Inherited::SetFrame(newFrame, invalidate);
  2130.     
  2131.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2132.     }
  2133.  
  2134. //
  2135. // AGATargetBorderViewMA ----------------------------------------------------
  2136. //
  2137.  
  2138. #undef Inherited
  2139. #define Inherited TTargetBorderView
  2140.  
  2141. MA_DEFINE_CLASS_M1(AGATargetBorderViewMA, Inherited);
  2142.  
  2143. void AGATargetBorderViewMA::IAGATargetBorderViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2144.     {
  2145.     this->ITargetBorderView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2146.     }
  2147.  
  2148. void AGATargetBorderViewMA::Draw(const VRect& area)
  2149.     {
  2150.     // Set the color, always draw. TTargetBorderView leaves
  2151.     // background unerased in 1-bit.
  2152.  
  2153.     GDIterator    iter;
  2154.     Boolean        deep;
  2155.     Boolean        isTarget = this->ContainsTarget(gApplication->GetTarget());
  2156.  
  2157.     CTemporaryRegion borderRegion;
  2158.     
  2159.     while (iter.More(deep))
  2160.         {
  2161.         if (deep)
  2162.             {
  2163.             if (isTarget)
  2164.                 ::RGBForeColor(&gAGARamp[r8]);
  2165.             else
  2166.                 ::RGBForeColor(&gAGARamp[r2]);
  2167.             }
  2168.         else
  2169.             {
  2170.             if (isTarget)
  2171.                 ::RGBForeColor(&gAGARamp[rB]);
  2172.             else
  2173.                 ::RGBForeColor(&gAGARamp[rW]);
  2174.             }
  2175.  
  2176.         this->ComputeBorderRegion(borderRegion);
  2177.         PaintRgn(borderRegion);
  2178.         }
  2179.     }
  2180.  
  2181. void AGATargetBorderViewMA::ComputeBorderRegion(RgnHandle borderRegion)
  2182.     {
  2183.     // Return the border region to be painted or invalidated.
  2184.  
  2185.     CRect                qdArea;
  2186.     CTemporaryRegion    innerRegion;
  2187.  
  2188.     this->GetQDExtent(qdArea);
  2189.     
  2190.     ::OpenRgn();
  2191.     ::FrameRoundRect(qdArea, 4, 4);
  2192.     ::CloseRgn(borderRegion);
  2193.  
  2194.     ::InsetRect(qdArea, 2, 2);
  2195.     ::RectRgn(innerRegion, qdArea);
  2196.     ::DiffRgn(borderRegion, innerRegion, borderRegion);
  2197.     }
  2198.  
  2199. //
  2200. // AGATargetBorderFrameViewMA ----------------------------------------------------
  2201. //
  2202.  
  2203. #undef Inherited
  2204. #define Inherited AGATargetBorderViewMA
  2205.  
  2206. MA_DEFINE_CLASS_M1(AGATargetBorderFrameViewMA, Inherited);
  2207.  
  2208. void AGATargetBorderFrameViewMA::IAGATargetBorderFrameViewMA(TDocument* itsDocument, TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, IDType itsTargetView)
  2209.     {
  2210.     this->IAGATargetBorderViewMA(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsTargetView);
  2211.     }
  2212.  
  2213. void AGATargetBorderFrameViewMA::Draw(const VRect& area)
  2214.     {
  2215.     // Let the AGATargetBorderViewMA draw the target border,
  2216.     // then draw the "3D" sunken frame portion..
  2217.  
  2218.     Inherited::Draw(area);
  2219.     
  2220.     CRect    qdArea;
  2221.  
  2222.     this->GetQDExtent(qdArea);
  2223.     
  2224.     ::InsetRect(qdArea, 3, 3);
  2225.  
  2226.     //
  2227.     // Draw the frame with shading outside.
  2228.     //
  2229.  
  2230.     enum { TL, Frame, BR, kNumColors };
  2231.  
  2232.     UInt8    colorIndex[kNumColors];
  2233.     
  2234.     GDIterator    iter;
  2235.     Boolean        deep;
  2236.  
  2237.     while (iter.More(deep))
  2238.         {
  2239.         if (deep)
  2240.             {
  2241.             if (this->IsEnabled())
  2242.                 {
  2243.                 colorIndex[TL] = r5;
  2244.                 colorIndex[Frame] = rB;
  2245.                 colorIndex[BR] = rW;
  2246.                 }
  2247.             else
  2248.                 {
  2249.                 colorIndex[TL] = r4;
  2250.                 colorIndex[Frame] = r10;
  2251.                 colorIndex[BR] = r1;
  2252.                 }
  2253.             }
  2254.         else    // 1-bit
  2255.             {
  2256.             colorIndex[Frame] = rB;
  2257.             
  2258.             if (! this->IsEnabled())
  2259.                 ::PenPat(&qd.gray);
  2260.             }
  2261.         
  2262.         ::RGBForeColor(&gAGARamp[colorIndex[Frame]]);
  2263.         ::InsetRect(qdArea, 1, 1);
  2264.         ::FrameRect(qdArea);
  2265.         ::InsetRect(qdArea, -1, -1);
  2266.         
  2267.         if (deep)
  2268.             {
  2269.             ::RGBForeColor(&gAGARamp[colorIndex[TL]]);
  2270.             ::MoveTo(qdArea.left, qdArea.bottom - 2);
  2271.             ::LineTo(qdArea.left, qdArea.top);
  2272.             ::LineTo(qdArea.right - 2, qdArea.top);
  2273.             
  2274.             ::RGBForeColor(&gAGARamp[colorIndex[BR]]);
  2275.             ::MoveTo(qdArea.left + 1, qdArea.bottom - 1);
  2276.             ::LineTo(qdArea.right - 1, qdArea.bottom - 1);
  2277.             ::LineTo(qdArea.right - 1, qdArea.top + 1);
  2278.             }
  2279.         else if (! this->IsEnabled())
  2280.             ::PenPat(&qd.black);
  2281.         }
  2282.  
  2283.     ::RGBForeColor(&gAGARamp[rB]);
  2284.     }
  2285.  
  2286. void AGATargetBorderFrameViewMA::Dim(const VRect& area)
  2287.     {
  2288.     // Suppress patBic painting over our frame.
  2289.     }
  2290.  
  2291. void AGATargetBorderFrameViewMA::SetEnable(Boolean state)
  2292.     {
  2293.     // Redraw now; unlike TControl, TView does not automatically
  2294.     // redraw when you disable/dim it.
  2295.     
  2296.     Inherited::SetEnable(state);
  2297.  
  2298.     if (this->Focus())
  2299.         {
  2300.         VRect    extent;
  2301.         
  2302.         this->GetExtent(extent);
  2303.         this->Draw(extent);
  2304.         }
  2305.     }
  2306.  
  2307. //
  2308. // AGAGroupBoxMA ----------------------------------------------------
  2309. //
  2310.  
  2311. #undef Inherited
  2312. #define Inherited TCluster
  2313.  
  2314. MA_DEFINE_CLASS_M1(AGAGroupBoxMA, Inherited);
  2315.  
  2316. AGAGroupBoxMA::AGAGroupBoxMA()
  2317.     {
  2318.     mAGAObject = NULL;
  2319.     }
  2320.  
  2321. AGAGroupBoxMA::~AGAGroupBoxMA()
  2322.     {
  2323.     // Delete AGA object if we successfully allocated it.
  2324.  
  2325.     if (mAGAObject != NULL)
  2326.         delete mAGAObject;
  2327.     }
  2328.  
  2329. void AGAGroupBoxMA::IAGAGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  2330.     {
  2331.     this->ICluster(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  2332.  
  2333.     this->CreateAGAObject();
  2334.     }
  2335.  
  2336. void AGAGroupBoxMA::DoPostCreate(TDocument* itsDocument)
  2337.     {
  2338.     // Create and set up the AGAObject.
  2339.  
  2340.     Inherited::DoPostCreate(itsDocument);
  2341.     
  2342.     this->CreateAGAObject();
  2343.     }
  2344.  
  2345. void AGAGroupBoxMA::CreateAGAObject()
  2346.     {
  2347.     // Instantiate the particular AGAObject subclass.
  2348.  
  2349.     CStr255    label;
  2350.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2351.     CRect    bounds;
  2352.     
  2353.     this->ViewToQDRect(viewRect, bounds);
  2354.     this->GetLabel(label);
  2355.  
  2356.     FailNIL(mAGAObject = new AGAGroupBox(bounds, AGATextStyle(fTextStyle), AGAGroupBox::kPrimaryGroupBox, label));
  2357.  
  2358.     if ((fUserArea != 0) && (fSuperView != NULL))
  2359.         {
  2360.         TView*    gapView = fSuperView->FindSubView(fUserArea);
  2361.  
  2362.         if (gapView != NULL)
  2363.             {
  2364.             CRect    gapExtent;
  2365.  
  2366.             gapView->GetQDExtent(gapExtent);
  2367.             mAGAObject->SetTitleGap(5 + gapExtent.GetLength(hSel));
  2368.             }
  2369.         }
  2370.     }
  2371.  
  2372. void AGAGroupBoxMA::Draw(const VRect& area)
  2373.     {
  2374.     // Let the AGAObject draw itself.
  2375.  
  2376.     if (mAGAObject != NULL)
  2377.         mAGAObject->DrawObject();
  2378.     }
  2379.  
  2380. void AGAGroupBoxMA::SetFrame(const VRect& newFrame, Boolean invalidate)
  2381.     {
  2382.     // Let the MacApp and AGA objects update their locations.
  2383.  
  2384.     Inherited::SetFrame(newFrame, invalidate);
  2385.     
  2386.     SetAGAObjectFrame(this, mAGAObject, newFrame, invalidate);
  2387.     }
  2388.  
  2389. void AGAGroupBoxMA::DoMouseCommand(VPoint& theMouse, TToolboxEvent* event, CPoint hysteresis)
  2390.     {
  2391.     // Group box drawing is based on enable state, but we don't
  2392.     // want clicking on the group box itself to cause highlighting.
  2393.     }
  2394.  
  2395. void AGAGroupBoxMA::DimState(Boolean state, Boolean redraw)
  2396.     {
  2397.     // Set the AGAObject's enable state.
  2398.  
  2399.     if (mAGAObject != NULL)
  2400.         {
  2401.         Boolean    wantRedraw = redraw && this->Focus();
  2402.  
  2403.         mAGAObject->SetEnable(!state, wantRedraw);
  2404.         }
  2405.     }
  2406.  
  2407. void AGAGroupBoxMA::Dim()
  2408.     {
  2409.     // Set the AGAObject's enable state, with immediate redraw.
  2410.  
  2411.     if (mAGAObject != NULL)
  2412.         mAGAObject->SetEnable(AGAObject::kDisabled, this->Focus());
  2413.     }
  2414.  
  2415. //
  2416. // AGASecondaryGroupBoxMA ----------------------------------------------------
  2417. //
  2418.  
  2419. #undef Inherited
  2420. #define Inherited AGAGroupBoxMA
  2421.  
  2422. MA_DEFINE_CLASS_M1(AGASecondaryGroupBoxMA, Inherited);
  2423.  
  2424. void AGASecondaryGroupBoxMA::IAGASecondaryGroupBoxMA(TView* itsSuperView, const VPoint& itsLocation, const VPoint& itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, ResNumber itsRsrcID, short itsIndex)
  2425.     {
  2426.     this->IAGAGroupBoxMA(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex);
  2427.     }
  2428.  
  2429. void AGASecondaryGroupBoxMA::CreateAGAObject()
  2430.     {
  2431.     // Instantiate the particular AGAObject subclass.
  2432.  
  2433.     CStr255    label;
  2434.     VRect    viewRect(0, 0, fSize.h, fSize.v);
  2435.     CRect    bounds;
  2436.     
  2437.     this->ViewToQDRect(viewRect, bounds);
  2438.     this->GetLabel(label);
  2439.  
  2440.     FailNIL(mAGAObject = new AGAGroupBox(bounds, AGATextStyle(fTextStyle), AGAGroupBox::kSecondaryGroupBox, label));
  2441.     }
  2442.  
  2443.